home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / prerror.c < prev    next >
C/C++ Source or Header  |  1980-01-01  |  4KB  |  140 lines

  1. /* prerror.c */
  2. /* handling errors */
  3.  
  4. #include <stdio.h>
  5. #include "prtypes.h"
  6.  
  7. #define CRPLEASE "Press Return"
  8.  
  9. extern char *Print_buffer;
  10. extern atom_ptr_t Predicate; /* from prlush.c */
  11.  
  12. /****************************************************************************
  13.             parserr()
  14.  A bit crude.
  15.  Parse error messages.
  16.  ****************************************************************************/
  17. char * parserr(s)
  18. char *s;
  19. {
  20.     extern char *Read_buffer;
  21.     extern FILE * Curr_infile;
  22.     extern unsigned int Inp_linecount;
  23.  
  24.     Read_buffer[80] = '\0'; /* dont print too much rubbish */
  25.     if(Curr_infile != stdin){
  26.         sprintf(Print_buffer, "Parse error,  line %d: %s %s\n", 
  27.                     Inp_linecount, s, Read_buffer);
  28.         }
  29.     else
  30.         sprintf(Print_buffer, "Parse error: %s %s\n", s, Read_buffer);
  31.     errmsg(Print_buffer);/* see machine dependent file */
  32.     return(NULL);
  33. }
  34.  
  35. /************************************************************************
  36.             fatal()
  37.  Deadly error().
  38.  Make sure  that the user has time to see this!
  39.  ************************************************************************/
  40. void fatal(s)
  41. char *s;
  42. {
  43.     sprintf(Print_buffer, "Fatal error %s\n", s);
  44.     errmsg(Print_buffer);
  45.     exit_term();
  46.     puts(CRPLEASE);
  47.     tty_getc();
  48.     exit(1);
  49. }
  50.  
  51. /************************************************************************
  52.             fatal2()
  53.  Deadly error().
  54.  Make sure  that the user has time to see this!
  55.  ************************************************************************/
  56. void fatal2(s,  s2)
  57. char *s, *s2;
  58. {
  59.     sprintf(Print_buffer, "Fatal error %s %s\n", s, s2);
  60.     errmsg(Print_buffer);
  61.     exit_term();
  62.     puts(CRPLEASE);
  63.     tty_getc();
  64.     exit(1);
  65. }
  66.  
  67. /************************************************************************
  68.             internal_error().
  69. If this gets called then you (or I) blew it in the C code.
  70. This is called by the macro INTERNAL_ERROR. 
  71.  ************************************************************************/
  72. void internal_error(filename, linenumber, s)
  73. char *filename, *s;
  74. int linenumber;
  75. {
  76.     sprintf(Print_buffer, "Internal Error in source file %s line %d %s\n", 
  77.         filename, linenumber, s);
  78.     errmsg(Print_buffer);
  79.     exit_term();
  80.     exit(2);
  81. }
  82.  
  83. /************************************************************************
  84.              argerr()
  85.  Called by builtins.
  86.  ************************************************************************/
  87. void argerr(narg, msg)
  88. int narg;
  89. char *msg;
  90. {
  91. sprintf(Print_buffer, "argument %d of %s bad should be %s\n", narg, ATOMPTR_NAME(Predicate), msg);
  92. errmsg(msg);
  93. }
  94.  
  95. /************************************************************************
  96.             nargerr()
  97.  Used by builtins.
  98.  ************************************************************************/
  99. nargerr(narg)
  100. int narg;
  101. {
  102. sprintf(Print_buffer, "Argument %d of %s expected; is missing\n",  narg,  ATOMPTR_NAME(Predicate));
  103. errmsg(Print_buffer);
  104. return(CRASH);
  105. }
  106.  
  107. /************************************************************************
  108.             typerr()
  109.  Used by builtins.
  110.  ************************************************************************/
  111. /* verify that this is in the the same order as in prtypes.h 
  112.  * or do something more complicated
  113.  */
  114. char *Typenames[] = 
  115. { "atom", "variable", "string", "integer", "pair", "clause"
  116. #ifdef REAL
  117.     ,"real"
  118. #endif
  119. #ifdef CHARACTER
  120.     ,"character"
  121. #endif 
  122. };
  123.  
  124. /* display a message saying the user has made a type error */
  125.  
  126. int typerr(narg, type)
  127. objtype_t type;
  128. {
  129. if(type < 0 || type > 5)
  130.   INTERNAL_ERROR("illegal type");
  131.  
  132. sprintf(Print_buffer, "argument %d of %s should be of type %s\n", 
  133.     narg, ATOMPTR_NAME(Predicate), Typenames[type]);
  134. errmsg(Print_buffer);
  135. return(CRASH);
  136. }
  137.  
  138. /* end of file */
  139.  
  140.